package com.neusoft.Shixun.controller;

import com.neusoft.Shixun.po.CareItem;
import com.neusoft.Shixun.po.LevelItem;
import com.neusoft.Shixun.po.ResponseBean;
import com.neusoft.Shixun.service.LevelItemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.logging.Level;

@RestController
@CrossOrigin("*")
@RequestMapping("/LevelItemController")
public class LevelItemController {

    @Autowired
    private LevelItemService levelItemService;

    @GetMapping
    public ResponseBean<List<LevelItem>> getAllLevelItems() {
        return levelItemService.getAllLevelItems();
    }

    @GetMapping("/{id}")
    public ResponseBean<LevelItem> getLevelItemById(@PathVariable Integer id) {
        return levelItemService.getLevelItemById(id);
    }

    @GetMapping("/getCareItemsByLevelId")
//    根据级别id查询该级别下的项目
    public ResponseBean<List<CareItem>> getCareItemsByLevelId(@RequestParam Integer id) {
        return levelItemService.getCareItemsByLevelId(id);
    }

    @GetMapping("/getCareItemsNotBelongsToLevelId")
//    根据级别id查询不在该级别下的项目
    public ResponseBean<List<CareItem>> getCareItemsNotBelongsToLevelId(@RequestParam Integer id) {
        return levelItemService.getCareItemsNotBelongsToLevelId(id);
    }

    @PostMapping("/addCareItemToLevelItem")
//    添加护理项目到某个护理级别中
    public ResponseBean<Integer> addCareItemToLevelItem(@RequestParam Integer careLevelId, @RequestParam Integer careItemId ) {
        return levelItemService.addCareItemToLevelItem(careLevelId, careItemId);
    }

    @PostMapping
    public ResponseBean<Integer> addLevelItem(@RequestBody LevelItem levelItem) {
        return levelItemService.addLevelItem(levelItem);
    }

    @PutMapping("/{id}")
    public ResponseBean<Integer> updateLevelItem(@PathVariable Integer id, @RequestBody LevelItem levelItem) {
        levelItem.setLevelItemId(id);
        return levelItemService.updateLevelItem(levelItem);
    }

    @DeleteMapping("/deleteLevelItem")
//    删除护理级别下的项目
    public ResponseBean<Integer> deleteLevelItem(@RequestParam Integer levelId, @RequestParam Integer itemId) {
        return levelItemService.deleteLevelItem(levelId, itemId);
    }


}